package com.xc.erp.modules.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.erp.common.utils.StringUtils;
import com.xc.erp.modules.erp.domain.pojo.JshSystemConfig;
import com.xc.erp.modules.erp.service.JshSystemConfigService;
import com.xc.erp.modules.erp.mapper.JshSystemConfigMapper;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class JshSystemConfigServiceImpl extends ServiceImpl<JshSystemConfigMapper, JshSystemConfig>
    implements JshSystemConfigService{

    @Override
    public Page<JshSystemConfig> list(Integer pageSize, Integer pageNum, String companyName) {
        Page<JshSystemConfig> jshSystemConfigPage = new Page<>(pageSize, pageNum);
        QueryWrapper<JshSystemConfig> queryWrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(companyName)){
            queryWrapper.like("company_name",companyName);
        }
        Page<JshSystemConfig> page = baseMapper.selectPage(jshSystemConfigPage, queryWrapper);
        return page;
    }

    @Override
    public boolean checkIsNameExist(Long id,String companyName) {
        QueryWrapper<JshSystemConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("company_name",companyName);
        JshSystemConfig jshSystemConfig = baseMapper.selectOne(queryWrapper);

        if (jshSystemConfig!=null){
            if (id!=null){
                if (id.equals(jshSystemConfig.getId())){
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}




